package mapi;

import io.renren.common.utils.AES128Util;

import org.apache.commons.codec.digest.DigestUtils;

import com.alibaba.fastjson.JSONObject;

public class test002 {
	
	public static void main(String[] args) throws Exception {
		testAES();
		
		
	}
	//商户请求参数
		private static void testAES() throws Exception {
			String merchantid="80000009";//商户编码
			String md5key="ced36bd3e499614b";
			String aeskey="655D5C2BB06CED85";
			
			Long timestamp=System.currentTimeMillis()/1000;//加密时间戳
			String sign=DigestUtils.md5Hex(merchantid+timestamp+md5key);
			JSONObject reqdata=new JSONObject(true);
			//云闪付
			/*reqdata.put("orderchannel", 3);
			reqdata.put("trscode", "dynamicunionpay");*/
			//微信
			/*reqdata.put("orderchannel", 0);
			reqdata.put("trscode", "wechat_dynamiccode");*/
			//支付宝红包
			/*reqdata.put("orderchannel", 1);
			reqdata.put("trscode", "zfbredbag");*/
			//支付宝动态二维码
			reqdata.put("orderchannel", 1);
			reqdata.put("trscode", "alipay_dmf");
			//支付宝转账二维码
			/*reqdata.put("orderchannel", 1);
			reqdata.put("trscode", "transfercode");
			//钉钉红包
			reqdata.put("orderchannel", 1);
			reqdata.put("trscode", "zfbredbag");*/
			reqdata.put("merchantorderid", System.currentTimeMillis());
			reqdata.put("applyamount",1);
			reqdata.put("web_username", "test001");
			reqdata.put("clienttype", "H5");
			reqdata.put("callbackurl"," ");
			System.out.println(reqdata);
			
			String data=AES128Util.encryptBase64(reqdata.toJSONString(), aeskey);
			System.out.println(data);
			
			JSONObject reqobj=new JSONObject();
			reqobj.put("merchantid", merchantid);
			reqobj.put("timestamp", timestamp);
			reqobj.put("sign", sign);
			reqobj.put("data", data);
			System.err.println("商户请求参数:"+reqobj);
			
			//测试解开data
			/*data="NmhqRVlTS0dJQmtMZ3hZWkQ5MnNzRWI3Y0FEbEFvV1RMMzdlbE1oYTNieHM2ZTJ4MU5mTjM2WUMzQ1U5dmdFdnZ2MDExUHpqbWM0bXlhRGFiVFhEYWVuNTFETHZOOThxajNHOGdZaTBneHlEYU5XOTlQRk9jRGxBRmlTU2RUUzZhMWhTM2Y4dk5OdnoyVWcvMnQ5YVBOS3JTVDBrRE1VVXQ2ajZPaEpMUkdlV3puVzgzRGF3VmVCaXBZL0xRenFoMlo1Vmg0UDB1ZTBNcmtiZzA2SFRoSCtWMXdKYzFSR0FtK084YjZmSHhHQlFNZjdwNXVmT0VST3l3TzYycGJYMnREMngvc3JObWtKckVUdU5VUUw1Nm4wc1NSL0w1T1J1eFBidzZVMFRBdG89";
			String resdatastr=AES128Util.decryptBase64(data, aeskey);
			JSONObject dataobj=JSONObject.parseObject(resdatastr);
			System.err.println(dataobj);
			
			 
			 System.out.println("############AES订单查询############");
			 
			 //AES订单查询
			 reqdata=new JSONObject();
			 reqdata.put("orderids", "2018120716061579339,2018120715562809798,2018120713191443653");
			 System.out.println(reqdata);
			 data=AES128Util.encryptBase64(reqdata.toJSONString(), aeskey);
			 System.out.println(data);
			 reqobj=new JSONObject();
			 reqobj.put("agentcode", agentcode);
			 reqobj.put("timestamp", timestamp);
			 reqobj.put("sign", sign);
			 reqobj.put("data", data);
			 System.err.println(reqobj);*/
			//{"amount":"0.30","billno":"ey45ZWkUmYUBk_fMgxBLvyaFqVop1rmoWLFd62OXGiU","channeltype":"0","paytime":"1550827040","paytype":"wechat","remark":"E3206DD04830ADB7"}
			

			String id="10000047";
			String usermd5key="326ef6ba201ae4fa";
			String useraeskey="1554A9640332F0AA";
			
			Long time=System.currentTimeMillis();
			JSONObject dataobj=new JSONObject();
			dataobj.put("amount", 400);
			dataobj.put("billno", System.currentTimeMillis());
			dataobj.put("paytype", "alipay");
			dataobj.put("remark", "");
			String endata=AES128Util.encryptBase64(dataobj.toJSONString(), useraeskey);
			String localsign=DigestUtils.md5Hex(endata+time+usermd5key);
			JSONObject callbackjson=new JSONObject();
			callbackjson.put("data", endata);
			callbackjson.put("id", id);
			callbackjson.put("time", time);
			callbackjson.put("sign", localsign);
			System.err.println("监控回调参数:"+callbackjson);
			
			
			System.err.println(String.format("¥0.20", "%d"));
			
			
		}
	

}
